﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Newtonsoft.Json;
using EasyUIMvc;

namespace EasyUIMvc.Samples.Controllers
{
    public class SampleController : Controller
    {
        //
        // GET: /Sample/

        public ActionResult Index()
        {
            return View();
        }

        #region " Menu 和 Button 系列 "
        public ActionResult Menu()
        {
            var MenuList = new List<MenuItem>(){
                new MenuItem("menu1"),
                new MenuItem("menu2"){
                    Childs=new List<MenuItem>(){
                        new MenuItem("menu3"),
                        new MenuItem("menu4")
                    }
                }
            };
            return View(MenuList);
        }
        public ActionResult LinkButton()
        {
            return View();
        }
        public ActionResult MenuButton()
        {
            List<MenuItem> MenuList = new List<MenuItem>();
            MenuItem menu1 = new MenuItem("menu1");
            MenuItem menu2 = new MenuItem("menu2");
            MenuItem menu3 = new MenuItem("menu3");
            MenuItem menu4 = new MenuItem("menu4");
            menu2.Childs.Add(menu3);
            menu2.Childs.Add(menu4);
            MenuList.Add(menu1);
            MenuList.Add(menu2);
            return View(MenuList);
        }
        #endregion

        #region " Form 系列 "

        public ActionResult ComboBox() {
            return View();
        }
        public ActionResult Calendar()
        {
            return View();
        }

        #endregion

        #region " Window 系列 "

        public ActionResult Window()
        {
            return View();
        }
        public ActionResult Messager()
        {
            return View();
        }

        #endregion

        #region " DataGird 和 Tree 系列 "

        public ActionResult DataGrid() {
            return View();
        }
        public ActionResult Tree()
        {
            return View();
        }

        #endregion

        public ActionResult Test() {
            var MenuList = new List<MenuItem>(){
                new MenuItem("menu1"),
                new MenuItem("menu2"){
                    Childs=new List<MenuItem>(){
                        new MenuItem("menu3"),
                        new MenuItem("menu4")
                    }
                }
            };
            return View(MenuList);
        }
        public JsonResult GetJson() {
            var jnlist = new List<JsonNode>();
            var jn1 = new JsonNode() { Id = "1", Name = "LY", Age = "18" };
            var jn2 = new JsonNode { Id = "2", Name = "YYY", Age = "17" };
            var jn3 = new JsonNode { Id = "3", Name = "test", Age = "12" };
            jnlist.Add(jn1);
            jnlist.Add(jn2);
            jnlist.Add(jn3);
            return Json(jnlist);
            //return JsonConvert.SerializeObject(jnlist, Formatting.Indented, new JsonSerializerSettings() { ReferenceLoopHandling = ReferenceLoopHandling.Ignore });
        }
        public JsonResult TreeData()
        {
            List<TreeNode> list = new List<TreeNode>() { 
                new TreeNode()
                {
                    text = "节点1",
                    id = "1",
                    state="open"
                },
                new TreeNode()
                {
                    text = "节点2",
                    id = "2",
                    state = "closed",
                    children = new List<TreeNode>(){
                        new TreeNode(){
                            text="子节点1",
                            id="21",
                            state="open"
                        },
                        new TreeNode(){
                            text="子节点2",
                            id="22",
                            state="open"
                        }
                    }
                }
            };
            return Json(list);
            //return JsonConvert.SerializeObject(list, Formatting.Indented, new JsonSerializerSettings() { ReferenceLoopHandling = ReferenceLoopHandling.Ignore });
        }
    }
    public class JsonNode {
        public string Id { get; set; }
        public string Name { get; set; }
        public string Age { get; set; }
    }
}
